<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>体育与健康课程管理系统</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/css/main.css"/>
    <link href="${pageContext.request.contextPath}/public/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/libs/modernizr.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/jquery-3.2.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/public/js/layer/layer.js"></script>
    <script src="${pageContext.request.contextPath}/public/laydate/laydate.dev.js"></script>
    <script src="${pageContext.request.contextPath}/public/bootstrap/js/bootstrap.min.js"></script>
</head>
<style type="text/css" media="screen">
.total{
    width:100%;
    height: 100%;
    background-color: #333;
    position: fixed;
    top:0px;
    opacity:0.5;
    margin:0px;
    z-index: 2;
    display:none;
}    
.add{
    width:400px;
    height:700px;
    background-color: #fff;
    position:absolute;
    top:50px;
    left:30%;
    border-radius: 5px;
z-index: 300;
display: none;
}
.add span
{
    float:right;
    font-size: 30px;
    margin-top: 10px;
    margin-right: 20px;
    color:#666;
    cursor: pointer;
}
.add span:hover
{
    color:#aaa;
}
.add p
{
    font-size: 18px;
    float:left;
    margin-top: 40px;
    margin-left:170px;
    color:#000;
    font-family: '微软雅黑';
    text-align: center;

}
.addtab
{
    float:left;
/*    margin-top:10px;*/
    margin-left: 50px;
}
.addtab tr
{
    float:left;
    margin-top: 20px;
    width:300px;
}
.addtab th
{
    width:90px;
    font-size: 15px;
    font-family: '微软雅黑';
    color:#000;
    float:left;
    font-weight:normal;
}
.addtab input
{
    border-radius: 5px;
    float:left;
    height:30px;
}
.btn12
{
    width:160px;
    height:40px;
    letter-spacing: 10px;
    font-size: 16px;
  
}
.require-red {
    color: #f60;
    font-family: serif;
    margin-right: 3px;
}
</style>
<body>
<div class="total">
</div>
<div class="add" id="add">
<span onclick="ad()">×</span>
<p>添加考试安排</p>
<form id="myformadd">
<table  class="addtab">
<tr><th><i class="require-red">*</i>考试名称：</th><td><input  name='peTestName' type='text'  placeholder="考试名称"></td></tr>
<tr><th><i class="require-red">*</i>考试描述：</th><td><textarea name="peTestAsk"  placeholder="考试要求"></textarea></td></tr>
<tr><th><i class="require-red">*</i>考试地点：</th><td><input  name='peTestPlace' type='text'  placeholder="考试地点"></td></tr>
<tr><th><i class="require-red">*</i>开始时间：</th><td><input  onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" name='peTestStarTime' class="laydate-icon" type='text'  placeholder="开始时间"></td></tr>
<tr><th><i class="require-red">*</i>结束时间：</th><td><input onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"  name='peTestEndTime' class="laydate-icon" type='text'  placeholder="结束时间"></td></tr>
<tr><th><i class="require-red">*</i>考试人数上限：</th><td><input onkeyup="value=value.replace(/[^\d.]/g,'')"  name='peTestUpperLimit' type='text'  placeholder="考试人数上限"></td></tr>
<tr><th><i class="require-red">*</i>考试人数下限：</th><td><input onkeyup="value=value.replace(/[^\d.]/g,'')" name='peTestLowerLimit' type='text'  placeholder="考试人数下限"></td></tr>
	<tr><th><i class="require-red">*</i>预约开始时间：</th><td><input  onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" name='orderStartTime' class="laydate-icon" type='text'  placeholder="预约开始时间"></td></tr>
	<tr><th><i class="require-red">*</i>预约结束时间：</th><td><input onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"  name='orderEndTime' class="laydate-icon" type='text'  placeholder="预约结束时间"></td></tr>
</table>
<input class="btn btn-primary btn6 btn12 suba" name="sub" value="添加" type="button" style="margin-left:140px;margin-top:20px">
</form>

</div>

<p style="margin-top:15px;margin-left:40px; font-size:16px; border-left:3px #006dcc solid; padding-left:5px">查看体能测试安排</p>
<div class="container clearfix" style="width:100%">
    <div class="main-wrap">
        <div class="search-wrap">
        	<div class="search-content">
        	<form method="post" action="${pageContext.request.contextPath}/petest/searchpetest.action">
        	 <table class="search-tab">
        	 	<th width="90" style="font-size:16px">考试名称:</th>
        	 	<td><input class="common-text" id="test" style="height:32px"  placeholder="考试名称" name="peTestName" type="text"></td>
        	 	 <td><input class="btn btn-primary btn2" name="sub" value="查询" type="submit"></td>
        	 </form>
        	 <form id="classform" action="${pageContext.request.contextPath}/petest/selectdate.action" method="post">
        	 	<th width="150px" style="font-size:16px">选择学期:</th>
        	 	<td>
        	 	<select name="systemYearId" style="width:120px;height:30px;border-radius:2%">
         			<option value="0">${nowyear }</option>
                    <c:forEach items="${systemyear }" var="x">
                     <option value="${x.systemYearId}">${x.systemYearName }</option>
                    </c:forEach>
                  </select>
				</td>
				<td><input class="btn btn-primary btn2" name="sub" value="查询" type="submit"></td>
        	 	</table>
        	 </form>
        	</div>
        </div>
        <div class="result-wrap" >
               <div class="result-title">
                    <div class="result-list">
                        <a href="javascript:;" onclick="ad()"><i class="icon-font"></i>新增考试安排</a>
                    </div>
                </div>
                <div class="result-content" id="app" >
                    <table class="result-tab" width="100%" style="font-size: 12px;">
                        <tr>
                            <th>序号</th>
                            <th>考试名称</th>
                            <!--  
                            <th>考试要求</th>
                            -->
                            <th>考试地点</th>
                            <th>考试时间</th>
                            <%--<th>开始时间</th>--%>
                            <%--<th>结束时间</th>--%>
                             <th>考试人数上限</th>
                            <th>考试人数下限</th>
							<th>预约开始时间</th>
							<th>预约结束时间</th>
                            <th>监考信息</th>
                            <th>操作</th>
                        </tr>
                      <c:forEach items="${data}" var="v" varStatus="status">
                        <tr >
                            <td>${status.index+1}</td>
                            <td>${v.peTestName}</td>
                            <!--  
                            <td>${v.peTestAsk}</td>
                            -->
                            <td>${v.peTestPlace}</td>
							<td><fmt:formatDate value="${v.peTestStarTime}" pattern="yyyy-MM-dd"/>　<fmt:formatDate value="${v.peTestStarTime}" pattern="HH:mm"/>-<fmt:formatDate value="${v.peTestEndTime}" pattern="HH:mm"/></td>
                            <%--<td><fmt:formatDate value="${v.peTestStarTime}" pattern="yyyy-MM-dd/HH:mm:ss"/> </td>--%>
                            <%--<td><fmt:formatDate value="${v.peTestEndTime}" pattern="yyyy-MM-dd/HH:mm:ss"/></td>--%>
                            <td>${v.peTestUpperLimit}</td>
                            <td>${v.peTestLowerLimit}</td>
							<td><fmt:formatDate value="${v.orderStartTime}" pattern="yyyy-MM-dd/HH:mm"/> </td>
							<td><fmt:formatDate value="${v.orderEndTime}" pattern="yyyy-MM-dd/HH:mm"/></td>
                           	<td><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal" onclick="show(${v.peTestId})">查看监考信息</button></td>
                            <td>
								<button type="button" class="btn btn-primary" onclick="copyone(${v.peTestId})">复制本条</button>
								<button type="button" class="btn btn-primary" onclick="showiframe(${v.peTestId})">查看预约学生</button>
								<button type="button" class="btn btn-success" onclick="upd(${v.peTestId})">修改</button>
								<button type="button" class="btn btn-danger" onclick="dele(${v.peTestId})">取消</button>
                            </tr>
  					</c:forEach>
                    </table>
                </div>
                </div>
               <div class="row">
				   <div class="col-md-3">当前${page.pageNow }页,总${page.totalPageCount }
					   页,总${page.totalCount}条记录</div>
                <div class="col-md-6">
				<nav aria-label="Page navigation">
				<%if(session.getAttribute("systemYearId")==null){ %>
				<ul class="pagination">
					<li><a href="${pageContext.request.contextPath}/petest/petest.action?pn=1">首页</a></li>
					<c:if test="${page.hasPre }">
						<li><a href="${pageContext.request.contextPath}/petest/petest.action?pn=${page.pageNow-1}"
							aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
						</a></li>
					</c:if>

					<li class="active"><a href="#">${page.pageNow}</a></li>
					<c:if test="${page.pageNow<page.totalPageCount }">
						<li><a href="${pageContext.request.contextPath}/petest/petest.action?pn=${page.pageNow+1}"
							aria-label="Next"> <span aria-hidden="true">&raquo;</span>
						</a></li>
					</c:if>
					<li><a href="${pageContext.request.contextPath}/petest/petest.action?pn=${page.totalPageCount}">末页</a></li>
				</ul>
			<%} else{ %>
				<ul class="pagination">
					<li><a href="${pageContext.request.contextPath}/petest/selectdate.action?pn=1&systemYearId=<%=session.getAttribute("systemYearId") %>">首页</a></li>
					<c:if test="${page.hasPre }">
						<li><a href="${pageContext.request.contextPath}/petest/selectdate.action?pn=${page.pageNow-1}&systemYearId=<%=session.getAttribute("systemYearId") %>"
							aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
						</a></li>
					</c:if>

					<li class="active"><a href="#">${page.pageNow}</a></li>
					<c:if test="${page.pageNow<page.totalPageCount }">
						<li><a href="${pageContext.request.contextPath}/petest/selectdate.action?pn=${page.pageNow+1 }&systemYearId=<%=session.getAttribute("systemYearId") %>"
							aria-label="Next"> <span aria-hidden="true">&raquo;</span>
						</a></li>
					</c:if>
					<li><a href="${pageContext.request.contextPath}/petest/selectdate.action?pn=${page.totalPageCount}&systemYearId=<%=session.getAttribute("systemYearId") %>">末页</a></li>
				</ul>
			<%
				session.removeAttribute("systemYearId");} %>
				</nav>
			</div>
			</div>

    </div>
</div>
<div  class="modal fade bs-example-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header" >
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
				</button>
				<h4 class="modal-title" id="myModalLabel">
					监考信息管理
				</h4>
			</div>
			<div style="margin:10px 20px; border:none">
				<lable><i class="require-red">*</i>监考老师：</lable> <input name="searchdemo"  placeholder="请输入老师姓名" class="common-text" onchange="addselect(this.value)" style="height:30px;width:120px"  />
				<select style="height:30px;border-radius:5%" id="addtea" name="userTeacherInfoId">
					<option value="">请选择</option>
				</select>
				<lable style="margin-left:15px"><i class="require-red">*</i>监考类型：</lable> 
				<select style="height:30px;border-radius:5%" name="invigilatorInfoType">
					<option value="">请选择</option>
					<option value="主考">主考</option>
					<option value="副考">副考</option>
					<option value="巡考">巡考</option>
				</select>
				<input class="btn btn-primary" name="sub" value="添加信息" type="button" onclick="addInvi()"  style="margin-left:15px;width:80px">
				
				<div style="margin-top:20px">
				<table class="result-tab" width="100%" id="addto">
					<tr>
                        <th>教师</th>
                        <th>监考类型</th>
                        <th>操作</th>
                   </tr>
                </table>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">
					关闭
				</button>
				<button type="button" class="btn btn-primary" data-dismiss="modal">
					提交
				</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->

</body>
<script>
   $(function () { $('#myModal').modal('hide')});
</script>
<script>
   $(function () { $('#myModal').on('hide.bs.modal', function () { })
   });
</script>
<script type="text/javascript">
function showiframe(id){
	   layer.open({
		      type: 2,
		      title: '体能测试预约考试学生',
		      shadeClose: true,
		      shade: false,
		      maxmin: true, //开启最大化最小化按钮
		      area: ['893px', '600px'],
		      content: 'http://pe.shzu.edu.cn/peindex/pc/admin.php/Invigilator/userlist_info?id='+id+'&type=tncs&is_yard=1'
		    });
}

function copyone(id){
    $.get("${pageContext.request.contextPath}/petest/copyone.action",{id:id},function(returndata){
        if(returndata.code==1)
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
                location.reload();
            });
        else
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:1000});

    });
}
function addselect(value)
{
	$('#addtea').html("<option value=''>请选择</option>");
	$.get("${pageContext.request.contextPath}/petest/searchteacher.action",{value:value},function(returndata){
		if(returndata.code==1)
			{
				var name;
				var id;
				var num;
				for(var i=0;i<returndata.data.teacherdata.length;i++){
						name=returndata.data.teacherdata[i]['userTeacherInfoName'];
						id=returndata.data.teacherdata[i]['userTeacherInfoId'];
						num=returndata.data.teacherdata[i]['userTeacherInfoNum'];
					$('#addtea').append("<option value='"+id+"'>"+name+"["+num+"]</option>");
				}
			}
	});
}

function deletejk(invigilatorInfoId,index)
{
	$.get("${pageContext.request.contextPath}/petest/deletejk.action",{invigilatorInfoId:invigilatorInfoId},function(returndata){
		if(returndata.code==1)
			$("#addto tr").eq(index+1).hide();	
		else
			layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:1000}); 
	});
	
}

function addInvi()
{
	var userTeacherInfoId=$('select[name=userTeacherInfoId]');
	var invigilatorInfoType=$('select[name=invigilatorInfoType]');
	if(userTeacherInfoId.val()=="")
	{
        layer.msg('监考老师不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        userTeacherInfoId.focus();
        return ;		
	}

	if(invigilatorInfoType.val()=="")
	{
        layer.msg('监考类型不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        invigilatorInfoType.focus();
        return ;		
	}
	$.post("${pageContext.request.contextPath}/petest/addinvigilatorinfo.action",{userTeacherInfoId:userTeacherInfoId.val(),invigilatorInfoType:invigilatorInfoType.val(),examId:examId},function(returndata){
		if(returndata.code==1){
			$("#addto").append("<tr><td>"+returndata.data.invigilatorInfo.userTeacherInfo.userTeacherInfoName+"["+returndata.data.invigilatorInfo.userTeacherInfo.userTeacherInfoNum+"]</td><td>"+returndata.data.invigilatorInfo.invigilatorInfoType+"</td><td><button type='button' class='btn btn-danger' onclick='deletejk("+returndata.data.invigilatorInfo.invigilatorInfoId+","+endi+")'>删除</button></td></tr>");
			endi=endi+1;
			}
			else
			layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:1000}); 
		
	});
}
function show(id)
{
	$('#addto').html("<tr><th>教师</th><th>监考类型</th><th>操作</th></tr>");
	$('#addtea').html("<option value=''>请选择</option>");
	examId=id;
	$.get("${pageContext.request.contextPath}/petest/selectjk.action",{examId:examId},function(returndata){
		var id;
		var name;
		var num;
		var type;
		for(var i=0;i<returndata.data.data.length;i++){
			id=returndata.data.data[i].invigilatorInfoId;
			name=returndata.data.data[i].userTeacherInfo.userTeacherInfoName;
			num=returndata.data.data[i].userTeacherInfo.userTeacherInfoNum;
			type=returndata.data.data[i].invigilatorInfoType;
			$("#addto").append("<tr><td>"+name+"["+num+"]</td><td>"+type+"</td><td><button type='button' class='btn btn-danger' onclick='deletejk("+id+","+i+")'>删除</button></td></tr>");
		}
		endi=returndata.data.data.length;
	});
}
	
function ad()
{
    $('.total').toggle(500);
    $('#add').toggle(1000);
}
function dele(id)
{
	$.get("${pageContext.request.contextPath}/petest/deletepetest.action",{id:id},function(returndata){
		if(returndata.code==1)
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
                location.reload(); 
              });
		else
			layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:1000}); 
	});
}

function upd(id)
{
	window.location.href="${pageContext.request.contextPath}/petest/update.action?id="+id;
}


$('.suba').click(function()
    {
		var peTestName=$('input[name=peTestName]');
		var peTestAsk=$('textarea[name=peTestAsk]');
		var peTestPlace=$('input[name=peTestPlace]');
		var peTestUpperLimit=$('input[name=peTestUpperLimit]');
		var peTestStarTime=$('input[name=peTestStarTime]');
		var peTestEndTime=$('input[name=peTestEndTime]');
		var peTestLowerLimit=$('input[name=peTestLowerLimit]');
        var orderStartTime=$('input[name=orderStartTime]');
        var orderEndTime=$('input[name=orderEndTime]');
	
		if(peTestName.val()=="")
		{
			layer.msg('考试名称不能为空', { offset: ['0px', '40%'], icon:7,time:2000});
			peTestName.focus();
			return ;
		}
		if(peTestAsk.val()=="")
		{
			layer.msg('考试要求不能为空', { offset: ['0px', '40%'], icon:7,time:2000});
			peTestAsk.focus();
			return ;
		}
		if(peTestPlace.val()=="")
		{
			layer.msg('考试地点不能为空', { offset: ['0px', '40%'], icon:7,time:2000});
			peTestPlace.focus();
			return ;
		}
		if(peTestUpperLimit.val()=="")
		{
			layer.msg('考试人数上限不能为空', { offset: ['0px', '40%'], icon:7,time:2000});
			peTestUpperLimit.focus();
			return ;
		}

		if(peTestStarTime.val()=="")
		{
			layer.msg('开始时间不能为空', { offset: ['0px', '40%'], icon:7,time:2000});
			peTestStarTime.focus();
			return ;
		}

		if(peTestEndTime.val()=="")
		{
			layer.msg('结束时间不能为空', { offset: ['0px', '40%'], icon:7,time:2000});
			peTestEndTime.focus();
			return ;
		}

		if(peTestLowerLimit.val()=="")
		{
			layer.msg('考试人数下限不能为空', { offset: ['0px', '40%'], icon:7,time:2000});
			peTestLowerLimit.focus();
			return ;
		}
        if(orderStartTime.val()=="")
        {
            layer.msg('预约开始时间不能为空', { offset: ['0px', '40%'], icon:7,time:2000});
            orderStartTime.focus();
            return ;
        }

        if(orderEndTime.val()=="")
        {
            layer.msg('预约结束时间不能为空', { offset: ['0px', '40%'], icon:7,time:2000});
            orderEndTime.focus();
            return ;
        }


        var formData = new FormData($("#myformadd")[0]);//获取表单数据
      $.ajax({
           url: "${pageContext.request.contextPath}/petest/insertpetest.action",//提交地址
           type: 'POST',
           data: formData,
           async: false,
           cache: false,
           processData: false,
           contentType: false,
           success: function (returndata) {
            if(returndata.code==1){
              layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
                location.reload(); 
              });
            }
            else
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});            
           },
           error: function (returndata) {
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});

       }
      });     

    });

</script>
</html>